package com.yeyks.controller.hotel;

import com.yeyks.common.ajax.AjaxResponseBody;
import com.yeyks.common.base.Arguments;
import com.yeyks.common.param.hotel.HotelRecommendCityAddParam;
import com.yeyks.common.param.hotel.HotelRecommendCityUpdateParam;
import com.yeyks.hotel.dal.domain.HotelRecommendCity;
import com.yeyks.hotel.service.HotelRecommendCityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author fuchangshuai
 * @since 2019-07-03
 */
@Api(tags = "推荐城市模块")
@RestController
@RequestMapping(value = "/recommend/hotel/city")
public class HotelRecommendCityController {

    @Autowired
    private HotelRecommendCityService cityService;

    @ApiOperation(value = "v4.3 --> 推荐城市列表", response = HotelRecommendCity.class)
    @PostMapping(value = "/list")
    public AjaxResponseBody<List<HotelRecommendCity>> cityList() {
        return AjaxResponseBody.success(cityService.list());
    }

    @ApiOperation(value = "v4.3 --> 推荐城市新增", notes = "根据true和false判断成功失败")
    @PostMapping(value = "/add")
    public AjaxResponseBody<Boolean> cityAdd(@Valid HotelRecommendCityAddParam param) {

        Boolean flag = cityService.insertCity(param);

        return AjaxResponseBody.success(flag);
    }

    @ApiOperation(value = "v4.3 --> 推荐城市编辑", notes = "根据true和false判断成功失败")
    @PostMapping(value = "/update")
    public AjaxResponseBody<Boolean> cityUpdate(@Valid HotelRecommendCityUpdateParam param) {

        Boolean flag = cityService.updateCity(param);
        return AjaxResponseBody.success(flag);
    }

    @ApiOperation(value = "v4.3 --> 推荐城市删除", notes = "根据true和false判断成功失败")
    @PostMapping(value = "/del")
    public AjaxResponseBody<Boolean> cityDel(Integer id) {
        Arguments.intIsNull(id, "推荐城市id不能为空");
        return AjaxResponseBody.success(cityService.removeById(id));
    }

    @ApiOperation(value = "v4.3 --> 同步城市经纬度", notes = "根据true和false判断成功失败")
    @PostMapping(value = "/sync/city/lat")
    public AjaxResponseBody<Boolean> syncCityLat() {

        return AjaxResponseBody.success(cityService.syncCityLat());
    }





}